/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package engine.ani;

import java.util.Hashtable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import mainpackage.Constant;
import mainpackage.GameBean;
import mainpackage.MainCanvas;
import mainpackage.MainLogic;
import mainpackage.MainView;
import mainpackage.ResManager;
import mainpackage.Tools;
import ui.UiInterFace;

/**
 *
 * @author Administrator
 */
public class Npc {
    //npc id

    public long[] shNpcIds;
    //速度
    public short[] shNpcSpeed;
    //名字
    public String[] strNpcNames;
    //等级
    public short[] shNpcLeves;
    //资源id
    public String[] strNpcResIds;
    //图片id
    public String[] strNpcImgIds;
    //难度
    public byte[] shNpcDifficulty;
    //高度
    public short[] shNpcHeight;
    //性别
    public byte[] shNpcgender;
    //type
    public short[] shNpcTypes;
    //位置 当前 xy 目标 xy
    public int[] iNpcXs, iNpcYs, iNpcOXs, iNpcOYs;
    //当前hp
    public short[] shNpcHps;
    //maxHp
    public short[] shNpcMaxHps;
    //当前mp
    public short[] shNpcMps;
    //maxMp
    public short[] shNpcMaxMps;
    //状态 
    public byte[] byNpcState;
    //动画
    public byte[] byNpcAction;
    //方向
    public byte[] byNpcDirection;
    //动画状态数组
    public int[][] iAniArrayNpc;
    //当前索引指针
    public short shNpcIndex;
    //资源初始化完毕
    public boolean blNpcResInitOver;
    //根据时间计算的移动步长
    private int iStep;
    //图片id缓冲
    public String[] strNpcResImgIdBuf;
    //动画id缓冲
    public String[] strNpcResAniIdBuf;
    //资源图片数据容器缓冲
    public byte[][] byNpcResImgDataBuf;
    //资源动画数据容器缓冲
    public byte[][] byNpcAniDataBuffer;
    //任务问号感叹号图标 0 无 1 黄？2 ！  3 灰问
    public byte[] byMssionView = null;
    //死亡
    public boolean[] blNpcIsDie;
    private boolean[] blNpcArrivedObj = null;
    //npc自动走停顿时间
    public long[] lNpcAutoRunStartTime = null;
    //npc容器
    public Hashtable repeatTable;
    //npc图片容器
//    public Hashtable npcImgTable;
//    //npc坐标
//    public int[] iNpcX = null;
//    public int[] iNpcY = null;
//    private Image imgShadow;
    private Image[] imgNewPlayer;
    //npc任务 问号感叹号动画
    public int aniNpcMission[][] = null;
    public int[][] iNpcAniPre;
    //npc死亡
    public int[] aniNpcDie = null;
    public int[] iNpcDiePos;
    private String[] StrName;//NPC的名字，带等级的
    public String strIds_send = "441";

    public Npc() {
        this.initNpc();
    }

    //初始化npc基本数据
    public void initNpc() {
        this.shNpcIds = new long[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.shNpcSpeed = new short[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.strNpcNames = new String[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.StrName = new String[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.shNpcLeves = new short[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.strNpcResIds = new String[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.strNpcImgIds = new String[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.shNpcDifficulty = new byte[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.shNpcHeight = new short[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.iNpcXs = new int[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.iNpcYs = new int[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.iNpcOXs = new int[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.iNpcOYs = new int[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.shNpcHps = new short[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.shNpcMaxHps = new short[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.shNpcMps = new short[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.shNpcMaxMps = new short[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.byNpcState = new byte[Constant.MAX_NPC_NUM_IN_SCREEN];//
        this.byNpcAction = new byte[Constant.MAX_NPC_NUM_IN_SCREEN];//byNpcAction
        this.byMssionView = new byte[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.byNpcDirection = new byte[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.shNpcTypes = new short[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.shNpcgender = new byte[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.blNpcIsDie = new boolean[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.blNpcArrivedObj = new boolean[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.iNpcAniPre = new int[Constant.MAX_NPC_NUM_IN_SCREEN][5];
        this.iNpcDiePos = new int[Constant.MAX_NPC_DIE_NUM_IN_SCREEN * 2];
        this.lNpcAutoRunStartTime = new long[Constant.MAX_NPC_NUM_IN_SCREEN];
        this.repeatTable = new Hashtable();
        for (int i = Constant.MAX_NPC_NUM_IN_SCREEN - 1; i >= 0; i--) {
            this.shNpcIds[i] = -1;
            this.shNpcSpeed[i] = -1;
            this.strNpcNames[i] = null;
            this.StrName[i] = null;
            this.shNpcLeves[i] = -1;
            this.strNpcResIds[i] = null;
            this.strNpcImgIds[i] = null;
            this.shNpcDifficulty[i] = -1;
            this.shNpcHeight[i] = -1;
            this.iNpcXs[i] = -1;
            this.iNpcYs[i] = -1;
            this.iNpcOXs[i] = -1;
            this.iNpcOYs[i] = -1;
            this.shNpcHps[i] = -1;
            this.shNpcMaxHps[i] = -1;
            this.shNpcMps[i] = -1;
            this.byNpcState[i] = -1;
            this.byNpcAction[i] = -1;
            this.byNpcDirection[i] = 1;
            this.shNpcTypes[i] = -1;
            this.shNpcgender[i] = -1;
            this.blNpcIsDie[i] = false;
            this.blNpcArrivedObj[i] = false;
            this.byMssionView[i] = 0;
            this.lNpcAutoRunStartTime[i] = -1;
        }
        try {
//            this.imgShadow = ResManager.createImage(90000072, Constant.RES_PUBLIC_FINAL, Constant.RES_UI_PATH, false, -1);
//            this.imgShadow = Tools.makeTransparent(this.imgShadow, 70);
            this.aniNpcMission = new int[Constant.MISSION_NOTEANI_MAX_NUMS][5];
            //#if NOKIA_S60V5
             this.imgNewPlayer = new Image[2];
             this.imgNewPlayer[0] = Tools.makeTransparent(ResManager.createImage(90000077), 255);
             //透明度
             this.imgNewPlayer[1] = Tools.makeTransparent(10, Constant.FONT_SMALL.getHeight() + 14, 220, 0x93b2ce);
            //#else
//#            this.imgNewPlayer = new Image[2];
//#            this.imgNewPlayer[0] = Tools.makeTransparent(ResManager.createImage(90000077), 255);
//#            //透明度
//#            this.imgNewPlayer[1] = Tools.makeTransparent(10, Constant.FONT_SMALL.getHeight() + 14, 220, 0x53b0ff);
            //#endif
        } catch (Exception ex) {
            if (Constant.DEBUG) {
                ex.printStackTrace();
            }
        }
    }

    public void clearNpc() {
        blHaveInitNpc = false;
        this.blNpcResInitOver = false;
        this.repeatTable = new Hashtable();
        this.strNpcResImgIdBuf = null;
        this.strNpcResAniIdBuf = null;
        for (int i = Constant.MAX_NPC_NUM_IN_SCREEN - 1; i >= 0; i--) {
            this.shNpcIds[i] = -1;
            this.strNpcNames[i] = null;
            this.StrName[i] = null;
            this.shNpcLeves[i] = -1;
            this.strNpcResIds[i] = null;
            this.strNpcImgIds[i] = null;
            this.shNpcDifficulty[i] = -1;
            this.shNpcHeight[i] = -1;
            this.iNpcXs[i] = -1;
            this.iNpcYs[i] = -1;
            this.iNpcOXs[i] = -1;
            this.iNpcOYs[i] = -1;
            this.shNpcHps[i] = -1;
            this.shNpcMaxHps[i] = -1;
            this.shNpcMps[i] = -1;
            this.byNpcState[i] = -1;
            this.byNpcAction[i] = -1;
            this.byNpcDirection[i] = -1;
            this.shNpcTypes[i] = -1;
            this.shNpcgender[i] = -1;
            this.blNpcIsDie[i] = false;
            this.blNpcArrivedObj[i] = false;
            this.byMssionView[i] = 0;
        }
        //默认为无符号
    }

    //初始化所有npc动画资源
    public void loadNpcRes() {
        try {
//            if (!MainLogic.blLogined) 

//else {
//                GameBean.SCREEN_TYPE = 2;
//                MainLogic.getInstance().send(Constant.MSG_NET_CMD_OPT_ON_SCREEN, Constant.SOCKET_MSG_TYPE_LOGIC);
//            }
            Tools.printLog("请求npc" + GameBean.SCREEN_TYPE);
            UiInterFace.byMaxLoadingNum = (byte) 100;
            MainLogic.gameMap.initOffSetXY(MainLogic.gamePlayer.iPlayerX, MainLogic.gamePlayer.iPlayerY);
            {
                GameBean.SCREEN_TYPE = 1;
                MainLogic.getInstance().send(Constant.MSG_NET_CMD_OPT_ON_SCREEN, Constant.SOCKET_MSG_TYPE_LOGIC);
                Tools.printLog("请求npc" + GameBean.SCREEN_TYPE);
//                GameBean.SCREEN_TYPE = 2;
//                MainLogic.getInstance().send(Constant.MSG_NET_CMD_OPT_ON_SCREEN, Constant.SOCKET_MSG_TYPE_LOGIC);
            }
//            if (this.strNpcResImgIdBuf != null) {
//                int imgNum = this.strNpcResImgIdBuf.length;
//                //创建npc图片池
//                for (int i = 0; i < imgNum; i++) {
//                    try {
//                        ResManager.createImage(Integer.parseInt(this.strNpcResImgIdBuf[i]), Constant.RES_PUBLIC_ONEROOM, this.byNpcResImgDataBuf[i]);
//                    } catch (Exception e) {
//                        if (Constant.DEBUG) {
//                            e.printStackTrace();
//                        }
//                    }
//                }
//            }
//            int aniNum = this.strNpcResAniIdBuf.length;
//            //创建npc动画文件
//            for (int i = 0; i < aniNum; i++) {
//                for (int j = 0; j < this.strNpcResAniIdBuf.length; j++) {
//                    if (this.strNpcResAniIdBuf[j] != null && this.strNpcResAniIdBuf[j].equals(this.strNpcResAniIdBuf[i])) {
////                        if (this.strNpcResAniIdBuf[i].equals("109")) {
//                        Tools.printLog("ANI" + this.strNpcResAniIdBuf[i]);
////                        }
////                        Tools.printLog("i" + i + "j" + j);
////                        if(!this.strNpcResAniIdBuf[i].equals("295"))
//                        ResManager.loadAnimation(Integer.parseInt(this.strNpcResAniIdBuf[i]), Constant.RES_PUBLIC_ONEROOM, this.byNpcAniDataBuffer[i], true);
//                    }
//                }
//            }
            //载入mission动画
            Tools.printLog("载入任务动画");
            Animation ani = ResManager.loadAnimation(Constant.RES_NPC_MISSION_ANI_PATH, Constant.RES_PUBLIC_FINAL, false);
            //0----没有 1----完成任务标记  2----可接任务标记  3----已接受未完成 4 已经完成未还
            if (ani != null) {
                ani.changeAction(0, 0, this.aniNpcMission[0]);// 可接任务标记 叹号
                ani.changeAction(1, 0, this.aniNpcMission[1]);// 可接任务标记 问号
            }
            if (MainLogic.getInstance().gamePlayer.byPlayerState != Constant.PLAYER_STATE_DIE)//如果玩家死亡
            {
                MainLogic.getInstance().gamePlayer.changeAction(Constant.PLAYER_STATE_STAND, MainLogic.getInstance().gamePlayer.byPlayerDirection, true, false);
            }
            Tools.printLog("载入任务动画结束");
            ani = null;
            this.strNpcResImgIdBuf = null;
            this.strNpcResAniIdBuf = null;
            this.byNpcResImgDataBuf = null;
            this.byNpcAniDataBuffer = null;
            this.blNpcResInitOver = true;
//            MainLogic.blLogined = true;
        } catch (Exception e) {
            this.strNpcResImgIdBuf = null;
            this.strNpcResAniIdBuf = null;
            this.byNpcResImgDataBuf = null;
            this.byNpcAniDataBuffer = null;
            this.blNpcResInitOver = true;
            MainLogic.blLogined = true;
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
    }
//测试用
    public static boolean blHaveInitNpc = false;

    public void addNPc(long npcId, String imgId, String AniId, short npcType, String npcName, short npclv, short hp,
            short maxHp, short mp, short maxMp, byte state, byte action, byte direct, int x, int y, short speed,
            byte missionview, byte npcDifficulty, short npcHeight, byte shNpcIndex) {
        try {
            ////////// 测试用////////////////////////
//            if(npcName.indexOf("山贼")== -1)
//                return;
//            if(blHaveInitNpc)
//                return;
//            blHaveInitNpc  = true;
            //////////////////////////////
            if (this.repeatTable.get(new Long(npcId)) != null) {
                int index = ((Integer) (this.repeatTable.get(new Long(npcId)))).intValue();
                if (index != -1) {
                    this.refreshNpc(index, npcId, npcType, npcName, npclv, hp, maxHp, mp, maxMp, state, action, direct, x, y, speed, missionview);
                }
                return;
            }
            if (this.shNpcIndex >= Constant.MAX_NPC_NUM_IN_SCREEN) {
                this.shNpcIndex = 0;
                while (this.shNpcIndex < Constant.MAX_NPC_NUM_IN_SCREEN && this.shNpcIds[this.shNpcIndex] != -1) {
                    this.shNpcIndex++;
                }
            }
            if (this.shNpcIndex >= Constant.MAX_NPC_NUM_IN_SCREEN) {
                return;
            }
            for (int i = 0; i < 5; i++) {
                this.iNpcAniPre[this.shNpcIndex][i] = 0;
            }
            this.shNpcIds[this.shNpcIndex] = npcId;
            this.repeatTable.put(new Long(npcId), new Integer(this.shNpcIndex));
            this.strNpcResIds[this.shNpcIndex] = AniId;
            this.shNpcTypes[this.shNpcIndex] = npcType;
            this.shNpcgender[this.shNpcIndex] = shNpcIndex;
            this.strNpcNames[this.shNpcIndex] = npcName;
            this.shNpcDifficulty[this.shNpcIndex] = npcDifficulty;
            this.shNpcLeves[this.shNpcIndex] = npclv;
//            if (this.shNpcTypes[this.shNpcIndex] == Constant.NPC_TYPE_CANATTACK) {
//                StrName[this.shNpcIndex] = "LV" + this.shNpcLeves[this.shNpcIndex] + " " + this.strNpcNames[this.shNpcIndex];
//            } else {
            StrName[this.shNpcIndex] = this.strNpcNames[this.shNpcIndex];
//            }
            this.shNpcHeight[this.shNpcIndex] = npcHeight;
            this.byNpcState[this.shNpcIndex] = state;
            this.iNpcXs[this.shNpcIndex] = x;
            this.iNpcYs[this.shNpcIndex] = y;
            this.iNpcOXs[this.shNpcIndex] = x;
            this.iNpcOYs[this.shNpcIndex] = y;
            if (speed > 0 && speed < 12) {
                speed = 12;
            }
            this.shNpcSpeed[this.shNpcIndex] = speed;
            this.byMssionView[this.shNpcIndex] = missionview;
            if (state == Constant.PLAYER_BIG_STATE_FIGHT) {
                this.changeAction(this.shNpcIndex, action, direct);
                Tools.printLog("npc第一次变状态战斗:" + "byNpcDirection" + direct + "name" + this.strNpcNames[this.shNpcIndex] + "this.strNpcResIds:" + this.strNpcResIds[this.shNpcIndex]);
            } else {
//                    for (int j = 0; j < 40; j++) {
//                    }
//                    this.byNpcDirection[this.shNpcIndex] = (byte) ((System.currentTimeMillis() + (this.shNpcIndex % 4 + Tools.random(1, 100))) % 4);
                this.changeAction(this.shNpcIndex, Constant.PLAYER_STATE_STAND, direct);
                Tools.printLog("npc第一次变状态:" + "byNpcDirection" + direct + "name" + this.strNpcNames[this.shNpcIndex] + "this.strNpcResIds:" + this.strNpcResIds[this.shNpcIndex]);
            }
            Tools.printLog("添加一个npc:" + this.shNpcIndex + "name" + this.strNpcNames[this.shNpcIndex] + "this.strNpcResIds:" + this.strNpcResIds[this.shNpcIndex] + "this.strNpcImgIds:" + this.strNpcImgIds[this.shNpcIndex] + "missionview:" + missionview);
            //如果有此图片
            //否则发要图片指令
            ResManager.loadAnimation(this.strNpcResIds[this.shNpcIndex], Constant.RES_PUBLIC_ONEROOM, true);
            if (this.shNpcIndex < Constant.MAX_NPC_NUM_IN_SCREEN) {
                this.shNpcIndex++;
                while (this.shNpcIndex < Constant.MAX_NPC_NUM_IN_SCREEN && this.shNpcIds[this.shNpcIndex] != -1) {
                    this.shNpcIndex++;
                }
            }
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
    }

    public void refreshNpcMission(long npcId, byte missionview) {
        if (this.repeatTable.get(new Long(npcId)) == null) {
            return;
        } else {
            int index = ((Integer) (this.repeatTable.get(new Long(npcId)))).intValue();
            if (index != -1) {
                this.byMssionView[index] = missionview;
            }
        }
    }

    public void refreshScreenNpc(long npcId, byte state, byte action, byte direct, int x, int y) {
        int index = -1;
        if (this.repeatTable.get(new Long(npcId)) == null) {
            return;
        } else {
            index = ((Integer) (this.repeatTable.get(new Long(npcId)))).intValue();
            if (index != -1) {
                this.byNpcState[index] = state;
                if (state == Constant.PLAYER_BIG_STATE_FIGHT) {
                    this.changeAction(index, action, direct);
                } else {
                    this.changeAction(index, Constant.PLAYER_STATE_STAND, direct);
                }
                this.iNpcOXs[index] = x;
                this.iNpcOYs[index] = y;
                this.iNpcXs[index] = x;
                this.iNpcYs[index] = y;
                if (state == 3) {
                    this.npcDie(index);
                    this.deleteNpc(index);
                }
            }
        }
    }
    //刷新npc如果和当前状态和方向相同暂不更新坐标

    public void refreshNpc(int index, long npcId, short npcType, String npcName, short npclv, short hp,
            short maxHp, short mp, short maxMp, byte state, byte action, byte direct, int x, int y, short speed, byte missionview) {
        this.byNpcState[index] = state;
//        this.byNpcAction[index] = action;
//        this.byNpcDirection[index] = direct;
        if (state == Constant.PLAYER_BIG_STATE_FIGHT) {
            this.changeAction(index, action, direct);
        } else {
            this.changeAction(index, Constant.PLAYER_STATE_STAND, direct);
        }
//            this.byNpcDirection[index] = (byte) ((System.currentTimeMillis() + (index + Tools.random(1, 100))) % 4);
//            this.changeAction(index, Constant.PLAYER_STATE_RUN, this.byNpcDirection[index]);
//        }
        this.iNpcOXs[index] = x;
        this.iNpcOYs[index] = y;
        this.iNpcXs[index] = x;
        this.iNpcYs[index] = y;
        this.byMssionView[index] = missionview;
        this.shNpcSpeed[index] = speed;
    }

    public void npcDie(int npcIndex) {
        if (npcIndex == -1 || this.repeatTable.get(new Long(this.shNpcIds[npcIndex])) == null) {
            return;
        }
        if (aniNpcDie == null) {
            aniNpcDie = new int[5];
            Tools.resetAniArray(0, aniNpcDie);
            ResManager.loadAnimation(Constant.RES_NPC_DIE_ANI_PATH, Constant.RES_PUBLIC_FINAL, false);
        }
        this.byNpcState[npcIndex] = Constant.PLAYER_STATE_DIE;
    }

    public void deleteNpc(int npcIndex) {
        try {
            if (shNpcIds[npcIndex] == MainLogic.iLockedObjNumber[0][0]) {
                MainLogic.getInstance().clearLockedObj(0, true);
            }
            Tools.resetAniArray(0, iNpcAniPre[npcIndex]);
            this.iNpcDiePos[0] = this.iNpcXs[npcIndex];
            this.iNpcDiePos[1] = this.iNpcYs[npcIndex];
            Tools.printLog("删除npc" + this.strNpcNames[npcIndex]);
            this.repeatTable.remove(new Long(this.shNpcIds[npcIndex]));
            this.shNpcIds[npcIndex] = -1;
            this.strNpcResIds[npcIndex] = null;
            this.shNpcTypes[npcIndex] = -1;
            this.shNpcgender[npcIndex] = -1;
            this.strNpcNames[npcIndex] = null;
            this.StrName[npcIndex] = null;
            this.shNpcDifficulty[npcIndex] = -1;
            this.shNpcHeight[npcIndex] = -1;
            this.byNpcDirection[npcIndex] = -1;
            this.iNpcOXs[npcIndex] = -1;
            this.iNpcOYs[npcIndex] = -1;
            this.byMssionView[npcIndex] = 0;
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
    }
    //更新npc

    public void updateNpc() {
        if (!MainLogic.blLogined) {
            return;
        }
        try {
            frameindex = 0;
            for (int i = Constant.MAX_NPC_NUM_IN_SCREEN - 1; i >= 0; i--) {
                if (shNpcIds[i] != -1) {

                    if (this.byNpcState[i] == Constant.PLAYER_BIG_STATE_FIGHT) {
                        switch (this.byNpcAction[i]) {
                            case Constant.PLAYER_STATE_RUN:
                                this.npcRun(i);
                                break;
                        }
                    } else if (this.shNpcTypes[i] == Constant.NPC_TYPE_CANATTACK) {
//                  Thread.currentThread().sleep(20);
                        for (int j = 0; j < 40; j++) {
                        }
                        this.npcAutoRun(i);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void npcRun(int index) {
//        if (!blNpcRun[index]) {
//            return;
//        }
        int iStep = this.shNpcSpeed[index] / 12;
        if (iStep <= 0) {
            return;
        }
        //测试
//         if (this.iNpcYs[index] < this.ObjYs[index])
//             this.iNpcYs[index] += iStep;
//         else
//             this.iNpcYs[index] -= iStep;
//         if (this.iNpcXs[index] < this.iObjXs[index])
//              this.iNpcXs[index] += iStep;
//         else
//              this.iNpcXs[index] -= iStep;
        switch (this.byNpcDirection[index]) {
            case Constant.PLAYER_DIRECTION_UP: //                if (this.iNpcYs[index] <= this.ObjYs[index]) {
            //                    this.iNpcYs[index] = this.ObjYs[index];
            ////                    ((Animation) (this.npcResAnis.get(strNpcResIds[index]))).changeAction(Constant.PLAYER_STATE_STAND, 0);
            ////                    this.changeAction(index, Constant.PLAYER_STATE_STAND, this.byNpcDirection[index]);
            //                    blNpcRun[index] = false;
            //                } else
            {
                this.iNpcYs[index] -= iStep;
            }
            break;
            case Constant.PLAYER_DIRECTION_DOWN: //                if (this.iNpcYs[index] >= this.ObjYs[index]) {
            //                    this.iNpcYs[index] = this.ObjYs[index];
            ////                      this.changeAction(index, Constant.PLAYER_STATE_STAND, this.byNpcDirection[index]);
            ////                    ((Animation) (this.npcResAnis.get(strNpcResIds[index]))).changeAction(Constant.PLAYER_STATE_STAND, 0);
            //                    blNpcRun[index] = false;
            //                } else
            {
                this.iNpcYs[index] += iStep;
            }
            break;
            case Constant.PLAYER_DIRECTION_LEFT: //                if (this.iNpcXs[index] <= this.iObjXs[index]) {
            //                    this.iNpcXs[index] = this.iObjXs[index];
            ////                      this.changeAction(index, Constant.PLAYER_STATE_STAND, this.byNpcDirection[index]);
            ////                    ((Animation) (this.npcResAnis.get(strNpcResIds[index]))).changeAction(Constant.PLAYER_STATE_STAND, 0);
            //                    blNpcRun[index] = false;
            //                } else
            {
                this.iNpcXs[index] -= iStep;
            }
            break;
            case Constant.PLAYER_DIRECTION_RIGHT: //                if (this.iNpcXs[index] >= this.iObjXs[index]) {
            //                    this.iNpcXs[index] = this.iObjXs[index];
            ////                    this.changeAction(index, Constant.PLAYER_STATE_STAND, this.byNpcDirection[index]);
            ////                    ((Animation) (this.npcResAnis.get(strNpcResIds[index]))).changeAction(Constant.PLAYER_STATE_STAND, 0);
            //                    blNpcRun[index] = false;
            //                } else
            {
                this.iNpcXs[index] += iStep;
            }
            break;
            case Constant.PLAYER_DIRECTION_UP_LEFT://向上
                this.iNpcXs[index] -= iStep;
                this.iNpcYs[index] -= iStep;
                break;
            case Constant.PLAYER_DIRECTION_UP_RIGHT://向上
                this.iNpcXs[index] += iStep;
                this.iNpcYs[index] -= iStep;
                break;
            case Constant.PLAYER_DIRECTION_DOWN_LEFT://向上
                this.iNpcXs[index] -= iStep;
                this.iNpcYs[index] += iStep;
                break;
            case Constant.PLAYER_DIRECTION_DOWN_RIGHT://向上
                this.iNpcXs[index] += iStep;
                this.iNpcYs[index] += iStep;
                break;
        }
    }

    /*
     * npc自动走
     */
    private int frameindex = 0;

    public void npcAutoRun(int index) {
        int iStep = 2;//(this.shNpcSpeed[index] / 12);
        if (iStep <= 0) {
            return;
        }
        frameindex += 1;
        if (frameindex % 2 == 1) {
            this.npcAutoAi(index, this.byNpcDirection[index]);
            if (this.byNpcAction[index] == Constant.PLAYER_STATE_RUN) {
                switch (this.byNpcDirection[index]) {
                    case Constant.PLAYER_DIRECTION_UP: {
                        this.iNpcYs[index] -= iStep;
                    }
                    break;
                    case Constant.PLAYER_DIRECTION_DOWN: {
                        this.iNpcYs[index] += iStep;
                    }
                    break;
                    case Constant.PLAYER_DIRECTION_LEFT: {
                        this.iNpcXs[index] -= iStep;
                    }
                    break;
                    case Constant.PLAYER_DIRECTION_RIGHT: {
                        this.iNpcXs[index] += iStep;
                    }
                    break;
//                 case Constant.PLAYER_DIRECTION_UP_LEFT://向上
//                     this.iNpcXs[index] -= iStep;
//                     this.iNpcYs[index] -= iStep;
//                 break;
//                  case Constant.PLAYER_DIRECTION_UP_RIGHT://向上
//                        this.iNpcXs[index] += iStep;
//                     this.iNpcYs[index] -= iStep;
//                 break;
//                 case Constant.PLAYER_DIRECTION_DOWN_LEFT://向上
//                        this.iNpcXs[index] -= iStep;
//                     this.iNpcYs[index] += iStep;
//                 break;
//                 case Constant.PLAYER_DIRECTION_DOWN_RIGHT://向上
//                       this.iNpcXs[index] += iStep;
//                     this.iNpcYs[index] += iStep;
//                break;
                }
            }
        }
    }
    /*
     * 获得方向
     */
    //NPC自动走范围
    private static final int NPC_AUTO_AI_X_DISTANCE = 16;
    private static final int NPC_AUTO_AI_Y_DISTANCE = 16;
    private static final byte NPC_AUTO_OX_WIDHT = 4;
    private static final byte NPC_AUTO_OY_HEIGHT = 4;

    public void npcAutoAi(int index, byte direct) {
//      if(this.iNpcXs[index] >= (this.iNpcOXs[index] + NPC_AUTO_OX_WIDHT) && this.iNpcXs[index] <= (this.iNpcOXs[index] - NPC_AUTO_OX_WIDHT)
//         &&this.iNpcYs[index] >= (this.iNpcOYs[index] + NPC_AUTO_OY_HEIGHT) && this.iNpcYs[index] <= (this.iNpcOYs[index] - NPC_AUTO_OY_HEIGHT)
//       )
        if (this.byNpcAction[index] == Constant.PLAYER_STATE_STAND && this.lNpcAutoRunStartTime[index] == -1) {
            this.byNpcDirection[index] = (byte) ((System.currentTimeMillis() + (this.shNpcIndex % 4 + Tools.random(1, 100))) % 4);
            this.lNpcAutoRunStartTime[index] = 0;
            this.changeAction(index, Constant.PLAYER_STATE_RUN, this.byNpcDirection[index]);
            return;
        }
        if (this.byNpcAction[index] == Constant.PLAYER_STATE_STAND && this.lNpcAutoRunStartTime[index] != 0)//计算时间
        {
//            Tools.printLog("npc站立" + strNpcNames[index]);
            if (System.currentTimeMillis() - this.lNpcAutoRunStartTime[index] > Tools.random(1000, 1000 + (index % 4) * 1000)) {
                this.lNpcAutoRunStartTime[index] = 0;
                this.changeAction(index, Constant.PLAYER_STATE_RUN, this.byNpcDirection[index]);
            } else {
                return;
            }
        } else if (this.byNpcAction[index] == Constant.PLAYER_STATE_RUN) {
            boolean blArriveObj = false;
            switch (direct) {
                case Constant.PLAYER_DIRECTION_UP: {
                    //如果到达原点
                    if (this.blNpcArrivedObj[index] && this.iNpcYs[index] <= this.iNpcOYs[index]) {
                        this.iNpcYs[index] = this.iNpcOYs[index];
                        this.blNpcArrivedObj[index] = false;
                        this.byNpcDirection[index] = (byte) ((System.currentTimeMillis() + (index + Tools.random(1, 100))) % 4);
                        blArriveObj = true;
                    } else if (this.iNpcYs[index] <= (this.iNpcOYs[index] - NPC_AUTO_AI_Y_DISTANCE)) {
                        this.blNpcArrivedObj[index] = true;
                        this.byNpcDirection[index] = Constant.PLAYER_DIRECTION_DOWN;
                    }
                }
                break;
                case Constant.PLAYER_DIRECTION_DOWN: {
                    //如果到达原点
                    if (this.blNpcArrivedObj[index] && this.iNpcYs[index] >= this.iNpcOYs[index]) {
                        this.iNpcYs[index] = this.iNpcOYs[index];
                        this.blNpcArrivedObj[index] = false;
                        this.byNpcDirection[index] = (byte) ((System.currentTimeMillis() + (index + Tools.random(1, 100))) % 4);
                        blArriveObj = true;
                    } else if (this.iNpcYs[index] >= (this.iNpcOYs[index] + NPC_AUTO_AI_Y_DISTANCE)) {
                        this.blNpcArrivedObj[index] = true;
                        this.byNpcDirection[index] = Constant.PLAYER_DIRECTION_UP;
                    }
                }
                break;
                case Constant.PLAYER_DIRECTION_LEFT: {
                    //如果到达原点
                    if (this.blNpcArrivedObj[index] && this.iNpcXs[index] <= this.iNpcOXs[index]) {
                        this.iNpcXs[index] = this.iNpcOXs[index];
                        this.blNpcArrivedObj[index] = false;
                        this.byNpcDirection[index] = (byte) ((System.currentTimeMillis() + (index + Tools.random(1, 100))) % 4);
                        blArriveObj = true;
                    } else if (this.iNpcXs[index] <= (this.iNpcOXs[index] - NPC_AUTO_AI_X_DISTANCE)) {
                        this.blNpcArrivedObj[index] = true;
                        this.byNpcDirection[index] = Constant.PLAYER_DIRECTION_RIGHT;
                    }
                }
                break;
                case Constant.PLAYER_DIRECTION_RIGHT: {
                    //如果到达原点
                    if (this.blNpcArrivedObj[index] && this.iNpcXs[index] >= this.iNpcOXs[index]) {
                        this.iNpcXs[index] = this.iNpcOXs[index];
                        this.blNpcArrivedObj[index] = false;
                        this.byNpcDirection[index] = (byte) ((System.currentTimeMillis() + (index + Tools.random(1, 100))) % 4);
                        blArriveObj = true;
                    } else if (this.iNpcXs[index] >= (this.iNpcOXs[index] + NPC_AUTO_AI_X_DISTANCE)) {
                        this.blNpcArrivedObj[index] = true;
                        this.byNpcDirection[index] = Constant.PLAYER_DIRECTION_LEFT;
                    }
                }
            }
            if (blArriveObj) {
                //到达原点
                this.lNpcAutoRunStartTime[index] = System.currentTimeMillis();
                if (this.byNpcDirection[index] == Constant.PLAYER_DIRECTION_UP) {
                    this.byNpcDirection[index] = Constant.PLAYER_DIRECTION_DOWN;
                }
                this.changeAction(index, Constant.PLAYER_STATE_STAND, this.byNpcDirection[index]);
//                Tools.printLog("NPC到原点变成站立");
            } else if (direct != this.byNpcDirection[index]) {
                this.changeAction(index, Constant.PLAYER_STATE_RUN, this.byNpcDirection[index]);
            }
        }
    }

    public void drawNpc(Graphics g, int i, int x, int y) {
        if (!this.blNpcResInitOver) {
            return;
        }
        if (shNpcIds[i] != -1 && ResManager.haveAni(strNpcResIds[i]) != -1) {
//                Tools.printLog(" this.strNpcNames"+ this.strNpcNames[i]+"npc strNpcResIds[i]:"+strNpcResIds[i]);
            if (this.shNpcgender[i] != 3 && this.shNpcgender[i] != 4) {
                if (MainLogic.getInstance().uiEquipment.isopenset[17]) {
                    g.drawImage(MainView.imgShadow, this.iNpcXs[i] - x - 16, this.iNpcYs[i] - y - 10, 0);
                }
            }
            //////////////////
            //#if NOKIA_S60V5
             if (MainLogic.first_touchNpc_fire) {
                 int inpc_W = this.shNpcHeight[i] * 2 / 3;
                 if ((this.iNpcXs[i] - inpc_W / 2) < (MainLogic.gameMap.iMapWorldOffsetX + MainCanvas.getPointerLogicX())
                         && (this.iNpcXs[i] + inpc_W / 2) > (MainLogic.gameMap.iMapWorldOffsetX + MainCanvas.getPointerLogicX())
                         && this.iNpcYs[i] > (MainLogic.gameMap.iMapWorldOffsetY + MainCanvas.getPointerLogicY())
                         && (this.iNpcYs[i] - this.shNpcHeight[i]) < (MainLogic.gameMap.iMapWorldOffsetY + MainCanvas.getPointerLogicY())) {
 //                    if (shNpcTypes[i] == Constant.NPC_TYPE_CANATTACK) {
                         MainLogic.istouchNpc_fire = true;
                         MainLogic.first_touchNpc_fire = false;
                         MainLogic.touchLockedObj_npcid = new long[8];
                         MainLogic.touchLockedObj_npcid[0] = shNpcIds[i];
                         MainLogic.touchLockedObj_npcid[1] = i;
                         MainLogic.touchLockedObj_npcid[2] = iNpcXs[i];
                         MainLogic.touchLockedObj_npcid[3] = iNpcYs[i];
                         MainLogic.touchLockedObj_npcid[4] = Constant.LOCKED_TYPE_NPC;
                         MainLogic.touchLockedObj_npcid[5] = 0;
                         MainLogic.touchLockedObj_npcid[6] = this.shNpcgender[i];
                         MainLogic.touchLockedObj_npcid[7] = Constant.NPC_TYPE_CANATTACK;
 
 //                    }
                 }
             }
             if (MainLogic.touchLockedObj_npcid != null) {
                 if (shNpcIds[i] == MainLogic.touchLockedObj_npcid[0]) {
                     MainLogic.touchLockedObj_npcid[2] = this.iNpcXs[i];
                     MainLogic.touchLockedObj_npcid[3] = this.iNpcYs[i];
                 }
             }
//#endif
            //////////////////////
            if (shNpcIds[i] == MainLogic.iLockedObjNumber[0][0]) {
//                MainLogic.getInstance().drawLockedObj(g, (this.iNpcXs[i] - x), (this.iNpcYs[i] - y));
                if (Math.abs(MainLogic.getInstance().gamePlayer.iPlayerX - this.iNpcXs[i]) > MainLogic.getInstance().iLockedPartW
                        || Math.abs(MainLogic.getInstance().gamePlayer.iPlayerY - this.iNpcYs[i]) > MainLogic.getInstance().iLockedPartH) {
                    MainLogic.getInstance().isLocked = true;
                } else {
                    MainLogic.iLockedObjNumber[0][2] = this.iNpcXs[i];
                    MainLogic.iLockedObjNumber[0][3] = this.iNpcYs[i];
                }
            }
            if (this.byNpcAction[i] == Constant.PLAYER_STATE_FIGHT) {
                if (this.iNpcAniPre[i][4] == 1) {
                    this.changeAction(i, Constant.PLAYER_STATE_STAND, this.byNpcDirection[i]);
                }
                ResManager.drawAnimation(ResManager.getAnimation(strNpcResIds[i], Constant.RES_PUBLIC_ONEROOM), this.iNpcAniPre[i], g, this.iNpcXs[i] - x, this.iNpcYs[i] - y, false);

            } else {
//                if (this.shNpcgender[i] != 4
//                        && MainLogic.getInstance().uiEquipment.isopenset[16]) {
//                    ResManager.drawAnimation(ResManager.getAnimation(strNpcResIds[i], Constant.RES_PUBLIC_ONEROOM), this.iNpcAniPre[i], g, this.iNpcXs[i] - x, this.iNpcYs[i] - y, true);
//                }
                if (!MainLogic.getInstance().uiEquipment.isopenset[16]
                        && this.shNpcgender[i] == 4) {
                } else {
//                    if(strNpcResIds[i].equals("348"))
//                        System.out.println("dfsfaf");
                    ResManager.drawAnimation(ResManager.getAnimation(strNpcResIds[i], Constant.RES_PUBLIC_ONEROOM), this.iNpcAniPre[i], g, this.iNpcXs[i] - x, this.iNpcYs[i] - y, true);
                }
            }
            //可以还任务
            if (this.byMssionView[i] == 1) {
                ResManager.drawAnimation(ResManager.getAnimation(Constant.RES_NPC_MISSION_ANI_PATH, Constant.RES_PUBLIC_FINAL), this.aniNpcMission[1], g, this.iNpcXs[i] - x, this.iNpcYs[i] - y - this.shNpcHeight[i] - Constant.FONT_SMALL_HEIGHT - 5, true);
            } //可以接任务
            else if (this.byMssionView[i] == 2) {
                ResManager.drawAnimation(ResManager.getAnimation(Constant.RES_NPC_MISSION_ANI_PATH, Constant.RES_PUBLIC_FINAL), this.aniNpcMission[0], g, this.iNpcXs[i] - x, this.iNpcYs[i] - y - this.shNpcHeight[i] - Constant.FONT_SMALL_HEIGHT - 5, true);
            } //接了还不能归还的任务

            if (this.shNpcgender[i] != 3 && this.shNpcgender[i] != 4) {
                if (MainLogic.getInstance().uiEquipment.isopenset[14]) {
                    //#if NOKIA_S40V3 || MOTO || K790 ||  NOKIA_S60V5 || NORMAL_240_400
                     Tools.drawShadowString(g, (byte) 0, this.StrName[i],
                             this.iNpcXs[i] - x - (Constant.FONT_SMALL.stringWidth(this.StrName[i]) >> 1),
                             this.iNpcYs[i] - y - this.shNpcHeight[i] - Constant.FONT_SMALL_HEIGHT - 5, 0xffcc00, 0x333333);
                    //#else
//#                    Tools.drawShadowString(g, (byte) 0, this.StrName[i],
//#                            this.iNpcXs[i] - x - (Constant.FONT_SMALL.stringWidth(this.StrName[i]) >> 1),
//#                            this.iNpcYs[i] - y - this.shNpcHeight[i] - Constant.FONT_SMALL_HEIGHT - 5, 0xffffff, 0x333333);
                    //#endif
                }
                if (MainLogic.getInstance().uiInterFace.sysMessage.StateGuide[0][0] == 0
                        && MainLogic.getInstance().uiInterFace.sysMessage.StateGuide[0][1] == 0
                        && MainLogic.getInstance().uiInterFace.sysMessage.saveStateGuide == 0) {
                    if (Math.abs(MainLogic.getInstance().gamePlayer.iPlayerX - this.iNpcXs[i]) < 30
                            && Math.abs(MainLogic.getInstance().gamePlayer.iPlayerY - this.iNpcYs[i]) < 30) {
                        if (this.StrName[i].equals("水岚（礼）")) {
                            MainLogic.getInstance().uiInterFace.sysMessage.initGuide("引导", 0, 1);
                            MainLogic.getInstance().uiInterFace.sysMessage.StateGuide[0][0] = 0;
                            MainLogic.getInstance().uiInterFace.sysMessage.StateGuide[0][1] = 1;
                            MainLogic.getInstance().uiInterFace.sysMessage.saveGuide(1);
                        }
                    }
                }
            }
            //
            if (this.strNpcResIds[i].equals(strIds_send)) {//绘制传送动画名字
                if (MainLogic.getInstance().uiEquipment.isopenset[14]) {
                    //#if NOKIA_S40V3 || MOTO || K790|| NOKIA_S60V5 || NORMAL_240_400
                     Tools.drawShadowString(g, (byte) 0, this.StrName[i],
                             this.iNpcXs[i] - x - (Constant.FONT_SMALL.stringWidth(this.StrName[i]) >> 1),
                             this.iNpcYs[i] - y - this.shNpcHeight[i] - Constant.FONT_SMALL_HEIGHT - 5, 0xffcc00, 0x333333);
                    //#else
//#                    Tools.drawShadowString(g, (byte) 0, this.StrName[i],
//#                            this.iNpcXs[i] - x - (Constant.FONT_SMALL.stringWidth(this.StrName[i]) >> 1),
//#                            this.iNpcYs[i] - y - this.shNpcHeight[i] - Constant.FONT_SMALL_HEIGHT - 5, 0xffffff, 0x333333);
                    //#endif

                }
            }
        } else if (this.byNpcState[i] == Constant.PLAYER_STATE_DIE) {
            if (aniNpcDie != null) {
//                    Tools.printLog("npc死亡啦");
                if (this.iNpcDiePos[0] > 0) {
                    if (aniNpcDie[4] == 1) {
                        Tools.resetAniArray(0, aniNpcDie);
                        this.iNpcDiePos[0] = -1;
                        this.byNpcState[i] = -1;
                        this.iNpcXs[i] = -1;
                        this.iNpcYs[i] = -1;
                    } else {
                        ResManager.drawAnimation(ResManager.getAnimation(Constant.RES_NPC_DIE_ANI_PATH, Constant.RES_PUBLIC_FINAL), this.aniNpcDie, g, this.iNpcXs[i] - x, this.iNpcYs[i] - y, false);
                    }
                    //可以接任务
                }
                //可以接任务
            }
        } else {
            aniNpcDie = new int[5];
            Tools.resetAniArray(0, aniNpcDie);
            ResManager.loadAnimation(Constant.RES_NPC_DIE_ANI_PATH, Constant.RES_PUBLIC_FINAL, false);
        }
    }
//    public void drawNpc(Graphics g, int x, int y) {
//        if (!this.blNpcResInitOver) {
//            return;
//        }
////        Animation ani;
//        for (int i = Constant.MAX_NPC_NUM_IN_SCREEN - 1; i >= 0; i--) {
//            if (shNpcIds[i] != -1 && this.npcResAnis.get(strNpcResIds[i]) != null) {
////                Tools.printLog(" this.strNpcNames"+ this.strNpcNames[i]+"npc strNpcResIds[i]:"+strNpcResIds[i]);
//                g.drawImage(this.imgShadow, this.iNpcXs[i] - x - 16, this.iNpcYs[i] - y - 10, 0);
//                if (shNpcIds[i] == MainLogic.iLockedObjNumber[0][0]) {
//                    MainLogic.getInstance().drawLockedObj(g, (this.iNpcXs[i] - x), (this.iNpcYs[i] - y));
//                }
//                ((Animation) (this.npcResAnis.get(strNpcResIds[i]))).show(g, this.iNpcXs[i] - x, this.iNpcYs[i] - y, this.iNpcAniPre[i], false, false);
//                if (this.byNpcAction[i] == Constant.PLAYER_STATE_FIGHT) {
//                    ((Animation) (this.npcResAnis.get(strNpcResIds[i]))).nextFrame(this.iNpcAniPre[i], false);
//                    if (this.iNpcAniPre[i][4] == 1) {
//                        this.changeAction(i, Constant.PLAYER_STATE_STAND, this.byNpcDirection[i]);
//                    }
//                } else {
//                    ((Animation) (this.npcResAnis.get(strNpcResIds[i]))).nextFrame(this.iNpcAniPre[i], true);
//                }
//                if (this.byMssionView[i] == 1) {
//                    //可以还任务
//                    this.aniNpcMission[0].show(g, this.iNpcXs[i] - x, this.iNpcYs[i] - y - 60);
//                    this.aniNpcMission[0].nextFrame(true);
//                } else if (this.byMssionView[i] == 2) {
//                    //可以接任务
//                    this.aniNpcMission[1].show(g, this.iNpcXs[i] - x, this.iNpcYs[i] - y - 60);
//                    this.aniNpcMission[1].nextFrame(true);
//                } else if (this.byMssionView[1] == 3) {
//                    //接了还不能归还的任务
//                    this.aniNpcMission[2].show(g, this.iNpcXs[i] - x, this.iNpcYs[i] - y - 60);
//                    this.aniNpcMission[2].nextFrame(true);
//                }
//                Tools.drawShadowString(g, this.StrName[i],
//                        this.iNpcXs[i] - x - (Constant.FONT_SMALL.stringWidth(this.StrName[i]) >> 1),
//                        this.iNpcYs[i] - y - this.shNpcHeight[i] - Constant.FONT_SMALL.getHeight() - 5, 0xffffff, 0x333333);
//
//            }
//        }
//        if (aniNpcDie != null) {
////         for(int i = Constant.MAX_NPC_DIE_NUM_IN_SCREEN -1; i >= 0; i--)
//            {
//                if (this.iNpcDiePos[0] > 0) {
//                    if (aniNpcDie.iAniStatus[4] == 1) {
//                        aniNpcDie = null;
//                        this.iNpcDiePos[0] = -1;
//                    } else {
//                        aniNpcDie.show(g, this.iNpcDiePos[0] - x, this.iNpcDiePos[1] - y - 30);
//                        aniNpcDie.nextFrame(false);
//                    }
//                }
//            }
//        }
//    }

    public void changeAction(int index, byte state, byte direct) {
        try {
            Animation npcAni = ResManager.getAnimation(strNpcResIds[index], Constant.RES_PUBLIC_ONEROOM);
            if (npcAni == null) {
                return;
            }
            {
                if (state == -1) {
                    return;
                }
                if (state != -1) {
                    if (state == 4 && (strNpcResIds[index].equals("120") || strNpcResIds[index].equals("295") || strNpcResIds[index].equals("300")))//
                    {
                        return;
                    }
                    if (this.byNpcState[index] == Constant.PLAYER_BIG_STATE_FIGHT && this.byNpcAction[index] == state && this.byNpcDirection[index] == direct) {
                        return;

                    } else {
                        this.byNpcAction[index] = state;
                        if (direct == -1) {
                            direct = this.byNpcDirection[index];
                        } else {
                            this.byNpcDirection[index] = direct;
                        }
                    }
                }
            }
            switch (state) {
                case Constant.PLAYER_STATE_STAND:
                    switch (direct) {
                        case Constant.PLAYER_DIRECTION_UP:
                            npcAni.changeAction(Constant.PLAYER_ACTION_ID_UP_STAND, 0, this.iNpcAniPre[index]);
                            break;
                        case Constant.PLAYER_DIRECTION_DOWN:
                            npcAni.changeAction(Constant.PLAYER_ACTION_ID_DOWN_STAND, 0, this.iNpcAniPre[index]);
                            break;
                        case Constant.PLAYER_DIRECTION_LEFT:
                            npcAni.changeAction(Constant.PLAYER_ACTION_ID_LEFT_STAND, 0, this.iNpcAniPre[index]);
                            break;
                        case Constant.PLAYER_DIRECTION_RIGHT:
                            npcAni.changeAction(Constant.PLAYER_ACTION_ID_RIGHT_STAND, 0, this.iNpcAniPre[index]);
                            break;
                    }
                    break;

                case Constant.PLAYER_STATE_RUN:
//                      if(this.strNpcNames[index].indexOf("招魂")!= -1)
//                    {
//                          Tools.printLog("direct"+direct+"objy"+this.ObjYs[index]+"cury"+this.iNpcYs[index]);
//                    }
                    switch (direct) {
                        case Constant.PLAYER_DIRECTION_UP:
                            npcAni.changeAction(Constant.PLAYER_ACTION_ID_UP_RUN, 0, this.iNpcAniPre[index]);
                            break;
                        case Constant.PLAYER_DIRECTION_DOWN:
                            npcAni.changeAction(Constant.PLAYER_ACTION_ID_DOWN_RUN, 0, this.iNpcAniPre[index]);
                            break;
                        case Constant.PLAYER_DIRECTION_LEFT:
                            npcAni.changeAction(Constant.PLAYER_ACTION_ID_LEFT_RUN, 0, this.iNpcAniPre[index]);
                            break;
                        case Constant.PLAYER_DIRECTION_RIGHT:
                            npcAni.changeAction(Constant.PLAYER_ACTION_ID_RIGHT_RUN, 0, this.iNpcAniPre[index]);
                            break;
                    }
                    break;

                case Constant.PLAYER_STATE_FIGHT:
//                    short actId = this.skillPlayer.getSkillActionId();
                    switch (direct) {
                        case Constant.PLAYER_DIRECTION_DOWN:
                            npcAni.changeAction(Constant.PLAYER_ACTION_ID_DOWN_FIGHT, 0, this.iNpcAniPre[index]);
                            break;
                        case Constant.PLAYER_DIRECTION_UP:
                            npcAni.changeAction(Constant.PLAYER_ACTION_ID_UP_FIGHT, 0, this.iNpcAniPre[index]);
                            break;
                        case Constant.PLAYER_DIRECTION_LEFT:
                            npcAni.changeAction(Constant.PLAYER_ACTION_ID_LEFT_FIGHT, 0, this.iNpcAniPre[index]);
                            break;
                        case Constant.PLAYER_DIRECTION_RIGHT:
                            npcAni.changeAction(Constant.PLAYER_ACTION_ID_RIGHT_FIGHT, 0, this.iNpcAniPre[index]);
                            break;
                    }
                    break;
                default:
                    switch (direct) {
                        case Constant.PLAYER_DIRECTION_DOWN:
                            npcAni.changeAction(state, 0, this.iNpcAniPre[index]);
                            break;
                        case Constant.PLAYER_DIRECTION_UP:
                            npcAni.changeAction(state + 1, 0, this.iNpcAniPre[index]);
                            break;
                        case Constant.PLAYER_DIRECTION_LEFT:
                            npcAni.changeAction(state + 2, 0, this.iNpcAniPre[index]);
                            break;
                        case Constant.PLAYER_DIRECTION_RIGHT:
                            npcAni.changeAction(state + 3, 0, this.iNpcAniPre[index]);
                            break;
                    }
                    break;

            }
//                  Tools.printLog("index"+index+"state"+state+"direct"+direct);
            npcAni = null;
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
    }

    public int getNpc(long id) {
//        if (this.repeatTable.get(new Long(npcId)) != null)
        if (id != -1 && (this.repeatTable.get(new Long(id)) != null)) {
            return ((Integer) (this.repeatTable.get(new Long(id)))).intValue();
        }
        return -1;
    }
//        for (int i = this.shNpcIds.length - 1; i
//                >= 0; i--) {
//            if (this.shNpcIds[i] == id) {
//                return i;
//            }
//        }
//        return -1;
//    }
}
